Home:ALL Converter>Testing decorated constructor parameters

Testing decorated constructor parameters

Ask Time:2018-11-17T08:36:03         Author:Ahmet Can Güven

Json Formatter

I am trying to test a class which uses inversify for dependency injection and using @inject() to decorate parameters.

@injectable()
export class SaveManager {
    constructor(
        @inject(INJECTABLE.STORAGE) storage: IStorage, //Uncovered Line: 15
        @inject(Configuration) configuration: Configuration //Uncovered Line: 16
    ) {
        this.storage = storage;
        this.configuration = configuration;
    }
}

But the branch coverage of this class shows me that:

    @inject(INJECTABLE.STORAGE) storage: IStorage, //Uncovered Line: 15
    @inject(Configuration) configuration: Configuration //Uncovered Line: 16

These lines are not covered.

File                     |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line  
SaveManager.ts           |      100 |    66.67 |      100 |      100 |          15,16 

What should I test here to achieve 100% coverage and how can I test a constructor parameter decorator?

I know that I can use container.get() but I should be able to test decorators too.

Author:Ahmet Can Güven,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53347101/testing-decorated-constructor-parameters
yy